package com.example.demo.dto;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 线程命名工厂
 * @author xiongshun
 * create time: 2020/7/16 21:11
 */
public class CommonThreadFactory implements ThreadFactory {
    private String preffix;
    private static AtomicInteger threadCount = new AtomicInteger(0);

    public CommonThreadFactory() {
        this.preffix = "api-default-";
    }
    public CommonThreadFactory(String name) {
        this.preffix = name + "-";
    }
    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, preffix + threadCount.incrementAndGet());
    }
}
